package main

import (
	"context"
	"encoding/json"
	"fmt"
	"github.com/sirupsen/logrus"
	"go.etcd.io/etcd/clientv3"
	"time"
)

type My struct {
	Path  string `json:"path"`
	Topic string `json:"topic"`
}

func main1() {
	p := My{}
	ss := `{"path":"d:\\老男孩\\logsAgent\\s4.log","topic":"web_log"}`
	err := json.Unmarshal([]byte(ss), &p)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(p)
}
func main() {
	client, err := clientv3.New(clientv3.Config{
		Endpoints:   []string{"127.0.0.1:2379"},
		RetryDialer: nil,
		DialTimeout: time.Second * 5,
		TLS:         nil,
	})
	if err != nil {
		fmt.Printf("connect to etcd failed,err :%v", err)
		return
	}
	fmt.Println("连接成功", client)
	defer client.Close()
	watchCh := client.Watch(context.Background(), "collect_log_key")
	for wresp := range watchCh {
		logrus.Info("get new conf from etcd!")
		for _, evt := range wresp.Events {
			fmt.Printf("type:%s key:%s value:%s\n", evt.Type, evt.Kv.Key, evt.Kv.Value)
		}
	}
}
